package com.feeyin.radar.crm.controller;

import com.feeyin.radar.commons.BigDecimalPropertyEditor;
import com.feeyin.radar.commons.DatePropertyEditor;
import com.feeyin.radar.commons.DateUtils;
import com.feeyin.radar.commons.Page;
import com.feeyin.radar.commons.StringUtils;
import com.feeyin.radar.crm.form.CustomerLimitForm;
import com.feeyin.radar.crm.model.Customer;
import com.feeyin.radar.crm.model.CustomerShare;
import com.feeyin.radar.crm.model.QueryCustomer;
import com.feeyin.radar.crm.service.ContractService;
import com.feeyin.radar.crm.service.CustomerService;
import com.feeyin.radar.crm.service.CustomerShareService;
import com.feeyin.radar.crm.service.CustomerUpdateHistoryService;
import com.feeyin.radar.crm.service.LinkmanService;
import com.feeyin.radar.crm.service.ManageReportService;
import com.feeyin.radar.crm.service.SaleRecordService;
import com.feeyin.radar.sys.service.AssessmentTypeService;
import com.feeyin.radar.sys.service.DepartmentService;
import com.feeyin.radar.sys.service.SaleStageSetService;
import com.feeyin.radar.sys.service.UserService;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
import org.springframework.web.servlet.view.RedirectView;

public class CustomerManageController extends MultiActionController
{
  private CustomerService customerService;
  private ManageReportService manageReportService;
  private CustomerShareService customerShareService;
  private UserService userService;
  private CustomerUpdateHistoryService customerUpdateHistoryService;
  private LinkmanService linkmanService;
  private SaleStageSetService saleStageSetService;
  private DepartmentService departmentService;
  private AssessmentTypeService assessmentTypeService;
  private ContractService contractService;
  private SaleRecordService saleRecordService;
  private String customerManage;
  private String addCustomer;
  private String updateCustomer;
  private String shareCustomer;
  private String updateShareCustomer;
  private String deptCustomer;
  private String customerDetail;
  private String advancedQuery;
  private String customerUpdateHistory;
  private String customerUpdateHistoryDetail;
  private String viewSaleInfo;
  private String deptAdvancedQuery;
  private String deptNameCustomer;
  private String advancedQueryNameCustomer;
  private String advancedQueryShareCustomer;
  private String advancedQueryNear;
  private String advancedQuerySucceedContract;
  private String advancedQueryMySucceedContract;
  private String advancedQueryMyHangUp;
  private String advancedQueryMyGiveUp;
  private String ownNameCustomer;
  private String myShareCustomer;
  private String nearViewCustomer;
  private String deptSaleRecordCustomer;
  private String deptSucceedContract;
  private String mySucceedContract;
  private String deptHangupBusinessOpportunity;
  private String myHangupBusinessOpportunity;
  private String deptGiveupBusinessOpportunity;
  private String myGiveupBusinessOpportunity;
  private String nearChangedBusinessOpportunity;
  private String nearFollowedBusinessOpportunity;
  private String nearUpdatedCustomer;

  public SaleRecordService getSaleRecordService()
  {
    return this.saleRecordService;
  }

  public void setSaleRecordService(SaleRecordService saleRecordService) {
    this.saleRecordService = saleRecordService;
  }

  public ContractService getContractService() {
    return this.contractService;
  }

  public void setContractService(ContractService contractService) {
    this.contractService = contractService;
  }

  public String getAdvancedQueryMyGiveUp()
  {
    return this.advancedQueryMyGiveUp;
  }

  public void setAdvancedQueryMyGiveUp(String advancedQueryMyGiveUp) {
    this.advancedQueryMyGiveUp = advancedQueryMyGiveUp;
  }

  public String getAdvancedQueryMyHangUp() {
    return this.advancedQueryMyHangUp;
  }

  public void setAdvancedQueryMyHangUp(String advancedQueryMyHangUp) {
    this.advancedQueryMyHangUp = advancedQueryMyHangUp;
  }

  public String getAdvancedQueryMySucceedContract() {
    return this.advancedQueryMySucceedContract;
  }

  public void setAdvancedQueryMySucceedContract(String advancedQueryMySucceedContract)
  {
    this.advancedQueryMySucceedContract = advancedQueryMySucceedContract;
  }

  public String getAdvancedQuerySucceedContract() {
    return this.advancedQuerySucceedContract;
  }

  public void setAdvancedQuerySucceedContract(String advancedQuerySucceedContract) {
    this.advancedQuerySucceedContract = advancedQuerySucceedContract;
  }

  public String getAdvancedQueryNear() {
    return this.advancedQueryNear;
  }

  public void setAdvancedQueryNear(String advancedQueryNear) {
    this.advancedQueryNear = advancedQueryNear;
  }

  public String getAdvancedQueryShareCustomer() {
    return this.advancedQueryShareCustomer;
  }

  public void setAdvancedQueryShareCustomer(String advancedQueryShareCustomer) {
    this.advancedQueryShareCustomer = advancedQueryShareCustomer;
  }

  public String getNearUpdatedCustomer() {
    return this.nearUpdatedCustomer;
  }

  public void setNearUpdatedCustomer(String nearUpdatedCustomer) {
    this.nearUpdatedCustomer = nearUpdatedCustomer;
  }

  public String getNearChangedBusinessOpportunity() {
    return this.nearChangedBusinessOpportunity;
  }

  public void setNearChangedBusinessOpportunity(String nearChangedBusinessOpportunity)
  {
    this.nearChangedBusinessOpportunity = nearChangedBusinessOpportunity;
  }

  public String getNearFollowedBusinessOpportunity() {
    return this.nearFollowedBusinessOpportunity;
  }

  public void setNearFollowedBusinessOpportunity(String nearFollowedBusinessOpportunity)
  {
    this.nearFollowedBusinessOpportunity = nearFollowedBusinessOpportunity;
  }

  public String getDeptGiveupBusinessOpportunity() {
    return this.deptGiveupBusinessOpportunity;
  }

  public void setDeptGiveupBusinessOpportunity(String deptGiveupBusinessOpportunity)
  {
    this.deptGiveupBusinessOpportunity = deptGiveupBusinessOpportunity;
  }

  public String getMyGiveupBusinessOpportunity() {
    return this.myGiveupBusinessOpportunity;
  }

  public void setMyGiveupBusinessOpportunity(String myGiveupBusinessOpportunity) {
    this.myGiveupBusinessOpportunity = myGiveupBusinessOpportunity;
  }

  public String getMyHangupBusinessOpportunity() {
    return this.myHangupBusinessOpportunity;
  }

  public void setMyHangupBusinessOpportunity(String myHangupBusinessOpportunity) {
    this.myHangupBusinessOpportunity = myHangupBusinessOpportunity;
  }

  public String getDeptHangupBusinessOpportunity() {
    return this.deptHangupBusinessOpportunity;
  }

  public void setDeptHangupBusinessOpportunity(String deptHangupBusinessOpportunity)
  {
    this.deptHangupBusinessOpportunity = deptHangupBusinessOpportunity;
  }

  public String getMySucceedContract() {
    return this.mySucceedContract;
  }

  public void setMySucceedContract(String mySucceedContract) {
    this.mySucceedContract = mySucceedContract;
  }

  public String getDeptSucceedContract() {
    return this.deptSucceedContract;
  }

  public void setDeptSucceedContract(String deptSucceedContract) {
    this.deptSucceedContract = deptSucceedContract;
  }

  public String getDeptSaleRecordCustomer() {
    return this.deptSaleRecordCustomer;
  }

  public void setDeptSaleRecordCustomer(String deptSaleRecordCustomer) {
    this.deptSaleRecordCustomer = deptSaleRecordCustomer;
  }

  public String getNearViewCustomer() {
    return this.nearViewCustomer;
  }

  public void setNearViewCustomer(String nearViewCustomer) {
    this.nearViewCustomer = nearViewCustomer;
  }

  public String getMyShareCustomer() {
    return this.myShareCustomer;
  }

  public void setMyShareCustomer(String myShareCustomer) {
    this.myShareCustomer = myShareCustomer;
  }

  public String getOwnNameCustomer() {
    return this.ownNameCustomer;
  }

  public void setOwnNameCustomer(String ownNameCustomer) {
    this.ownNameCustomer = ownNameCustomer;
  }

  public String getAdvancedQueryNameCustomer() {
    return this.advancedQueryNameCustomer;
  }

  public void setAdvancedQueryNameCustomer(String advancedQueryNameCustomer) {
    this.advancedQueryNameCustomer = advancedQueryNameCustomer;
  }
  public ManageReportService getManageReportService() {
    return this.manageReportService;
  }

  public void setManageReportService(ManageReportService manageReportService) {
    this.manageReportService = manageReportService;
  }
  public String getDeptNameCustomer() {
    return this.deptNameCustomer;
  }

  public void setDeptNameCustomer(String deptNameCustomer) {
    this.deptNameCustomer = deptNameCustomer;
  }

  public CustomerService getCustomerService() {
    return this.customerService;
  }

  public void setCustomerService(CustomerService customerService) {
    this.customerService = customerService;
  }

  public CustomerShareService getCustomerShareService() {
    return this.customerShareService;
  }

  public void setCustomerShareService(CustomerShareService customerShareService) {
    this.customerShareService = customerShareService;
  }

  public UserService getUserService() {
    return this.userService;
  }

  public void setUserService(UserService userService) {
    this.userService = userService;
  }

  public CustomerUpdateHistoryService getCustomerUpdateHistoryService() {
    return this.customerUpdateHistoryService;
  }

  public void setCustomerUpdateHistoryService(CustomerUpdateHistoryService customerUpdateHistoryService)
  {
    this.customerUpdateHistoryService = customerUpdateHistoryService;
  }

  public LinkmanService getLinkmanService() {
    return this.linkmanService;
  }

  public void setLinkmanService(LinkmanService linkmanService) {
    this.linkmanService = linkmanService;
  }

  public SaleStageSetService getSaleStageSetService() {
    return this.saleStageSetService;
  }

  public void setSaleStageSetService(SaleStageSetService saleStageSetService) {
    this.saleStageSetService = saleStageSetService;
  }

  public DepartmentService getDepartmentService() {
    return this.departmentService;
  }

  public void setDepartmentService(DepartmentService departmentService) {
    this.departmentService = departmentService;
  }

  public AssessmentTypeService getAssessmentTypeService() {
    return this.assessmentTypeService;
  }

  public void setAssessmentTypeService(AssessmentTypeService assessmentTypeService) {
    this.assessmentTypeService = assessmentTypeService;
  }

  public String getCustomerManage() {
    return this.customerManage;
  }

  public void setCustomerManage(String customerManage) {
    this.customerManage = customerManage;
  }

  public String getAddCustomer() {
    return this.addCustomer;
  }

  public void setAddCustomer(String addCustomer) {
    this.addCustomer = addCustomer;
  }

  public String getUpdateCustomer() {
    return this.updateCustomer;
  }

  public void setUpdateCustomer(String updateCustomer) {
    this.updateCustomer = updateCustomer;
  }

  public String getDeptCustomer() {
    return this.deptCustomer;
  }

  public void setDeptCustomer(String deptCustomer) {
    this.deptCustomer = deptCustomer;
  }

  public String getShareCustomer() {
    return this.shareCustomer;
  }

  public void setShareCustomer(String shareCustomer) {
    this.shareCustomer = shareCustomer;
  }

  public String getUpdateShareCustomer() {
    return this.updateShareCustomer;
  }

  public void setUpdateShareCustomer(String updateShareCustomer) {
    this.updateShareCustomer = updateShareCustomer;
  }

  public String getCustomerDetail() {
    return this.customerDetail;
  }

  public void setCustomerDetail(String customerDetail) {
    this.customerDetail = customerDetail;
  }

  public String getAdvancedQuery() {
    return this.advancedQuery;
  }

  public void setAdvancedQuery(String advancedQuery) {
    this.advancedQuery = advancedQuery;
  }

  public String getCustomerUpdateHistory() {
    return this.customerUpdateHistory;
  }

  public void setCustomerUpdateHistory(String customerUpdateHistory) {
    this.customerUpdateHistory = customerUpdateHistory;
  }

  public String getCustomerUpdateHistoryDetail() {
    return this.customerUpdateHistoryDetail;
  }

  public void setCustomerUpdateHistoryDetail(String customerUpdateHistoryDetail) {
    this.customerUpdateHistoryDetail = customerUpdateHistoryDetail;
  }

  public String getViewSaleInfo() {
    return this.viewSaleInfo;
  }

  public void setViewSaleInfo(String viewSaleInfo) {
    this.viewSaleInfo = viewSaleInfo;
  }

  public String getDeptAdvancedQuery() {
    return this.deptAdvancedQuery;
  }

  public void setDeptAdvancedQuery(String deptAdvancedQuery) {
    this.deptAdvancedQuery = deptAdvancedQuery;
  }

  public ModelAndView display(HttpServletRequest request, HttpServletResponse response, QueryCustomer queryCustomer)
  {
    Integer userId = (Integer)request.getSession().getAttribute("userId");
    Map map = new HashMap();
    map.put("deleteResult", request.getParameter("deleteResult"));

    String sFlag = request.getParameter("sFlag");

    String viewType = "";
    if ((!StringUtils.isEmpty(sFlag)) && ("1".equals(sFlag))) {
      viewType = request.getParameter("viewType");
    }
    map.put("viewType", viewType);

    QueryCustomer qCustomer = null;
    if ((!StringUtils.isEmpty(sFlag)) && ("2".equals(sFlag))) {
      qCustomer = queryCustomer;
    }
    map.put("sFlag", sFlag);

    String sortSign = request.getParameter("sortSign");
    if ((!StringUtils.isEmpty(sortSign)) && ("1".equals(sortSign))) {
      qCustomer = queryCustomer;
    }
    map.put("sortSign", sortSign);
    map.put("imgId", request.getParameter("imgId"));
    map.put("queryCustomer", qCustomer);

    Page page = new Page();
    page.getPageList(this.customerService.getPageMyCustomersCount(viewType, userId, qCustomer).intValue(), null, request);
    map.put("customers", this.customerService.getPageMyCustomers(viewType, userId, page, qCustomer));

    CustomerLimitForm customerLimitForm = new CustomerLimitForm();
    customerLimitForm = this.customerService.getCustomerLimit(userId);
    if (!this.assessmentTypeService.isExpUser(userId)) {
      if ((customerLimitForm != null) && 
        (customerLimitForm.getCurrentCustomerNum() >= customerLimitForm.getTotalCustomerLimit()))
        map.put("notAdd", "1");
    }
    else {
      map.put("isExpUser", "1");
    }
    map.put("customerLimitForm", customerLimitForm);
    map.put("discardLimitNum", this.customerService.getDiscardCustomerNum(userId));
    map.put("ranges", this.customerService.getCustomerDictionaryRanges());

    return new ModelAndView(getCustomerManage(), map);
  }

  public ModelAndView deptCustomer(HttpServletRequest request, HttpServletResponse response, QueryCustomer queryCustomer)
  {
    Map map = new HashMap();
    Integer userId = (Integer)request.getSession().getAttribute("userId");
    map.put("deleteResult", request.getParameter("deleteResult"));

    String sFlag = request.getParameter("sFlag");

    QueryCustomer qCustomer = null;
    if ((!StringUtils.isEmpty(sFlag)) && ("2".equals(sFlag))) {
      qCustomer = queryCustomer;
    }
    map.put("sFlag", sFlag);

    String sortSign = request.getParameter("sortSign");
    if ((!StringUtils.isEmpty(sortSign)) && ("1".equals(sortSign))) {
      qCustomer = queryCustomer;
    }
    map.put("sortSign", sortSign);
    map.put("imgId", request.getParameter("imgId"));
    map.put("queryCustomer", qCustomer);

    Page page = new Page();
    page.getPageList(this.customerService.getPageDeptCustomerCount(userId, qCustomer).intValue(), null, request);
    map.put("customers", this.customerService.getPageDeptCustomers(userId, page, qCustomer));
    map.put("ranges", this.customerService.getCustomerDictionaryRanges());

    return new ModelAndView(getDeptCustomer(), map);
  }

  public ModelAndView preAddCustomer(HttpServletRequest request, HttpServletResponse response)
  {
    Map map = new HashMap();

    map.put("result", request.getParameter("result"));
    map.put("repeat", request.getAttribute("repeat"));
    map.put("records", this.customerService.getCustomerInfoRecords());
    map.put("ranges", this.customerService.getCustomerDictionaryRanges());
    map.put("customerCode", DateUtils.getDateByFormat("yyyyMMddHHmmss"));

    return new ModelAndView(getAddCustomer(), map);
  }

  public ModelAndView addCustomer(HttpServletRequest request, HttpServletResponse response, Customer customer)
  {
    boolean result = false;
    int success = 0;

    if (customer != null) {
      List list = new ArrayList();
      list = this.customerService.isRepeatSet();
      if ((list != null) && (list.size() > 0))
      {
        if (this.customerService.isRepeatAddCustomer(customer)) {
          request.setAttribute("repeat", Integer.valueOf(1));
          request.setAttribute("customer", customer);

          return preAddCustomer(request, response);
        }
      }

      if (!this.assessmentTypeService.isExpUser(customer.getSalePersonId())) {
        CustomerLimitForm customerLimitForm = new CustomerLimitForm();
        customerLimitForm = this.customerService.getCustomerLimit(customer.getSalePersonId());
        if ((customerLimitForm != null) && 
          (customerLimitForm.getCurrentCustomerNum() >= customerLimitForm.getTotalCustomerLimit())) {
          request.setAttribute("notAdd", Integer.valueOf(1));
          request.setAttribute("customer", customer);

          return preAddCustomer(request, response);
        }
      }

      result = this.customerService.insertCustomer(customer);
      if (result) success = 1;
    }

    return new ModelAndView(new RedirectView("./customerManage.do?action=preAddCustomer&result=" + success));
  }

  public ModelAndView preUpdateCustomer(HttpServletRequest request, HttpServletResponse response)
  {
    Map map = new HashMap();
    map.put("sign", request.getParameter("sign"));
    map.put("result", request.getParameter("result"));
    map.put("repeat", request.getAttribute("repeat"));
    map.put("records", this.customerService.getCustomerInfoRecords());
    map.put("ranges", this.customerService.getCustomerDictionaryRanges());
    
    String id = request.getParameter("id");
    if (!StringUtils.isEmpty(id)) 
    {    
      String realPath = realPath = getServletContext().getRealPath("/");
      map.put("customerAddes", this.customerService.getCustomerAddedsById(realPath, Integer.parseInt(id)));
      map.put("customer", this.customerService.getCustomerById(Integer.valueOf(Integer.parseInt(id))));
    }

    return new ModelAndView(getUpdateCustomer(), map);
  }
  
  public ModelAndView deleteAdded(HttpServletRequest request, HttpServletResponse response) {
	    String realPath = getServletContext().getRealPath("/");
	    String sign = request.getParameter("sign");
	    String customerId = request.getParameter("id");
	    String addedId = request.getParameter("addedId");
	    boolean result = false;
	    int success = 0;
	    if (!StringUtils.isEmpty(addedId)) {
	      result = this.contractService.deleteAdded(realPath, Integer.valueOf(Integer.parseInt(addedId)));
	      if (result) success = 1;
	    }
	    return new ModelAndView(new RedirectView("./customerManage.do?action=preUpdateCustomer&id=" + customerId + "&deleteResult=" + success + "&sign=" + sign));
  }

  public ModelAndView updateCustomer(HttpServletRequest request, HttpServletResponse response, Customer customer)
  {
    boolean result = false;
    int success = 0;
    int id = 0;
    String sign = request.getParameter("sign");
    
    Integer userId = (Integer)request.getSession().getAttribute("userId");
    customer.setPersonId(userId);
    if (customer != null) {
      id = customer.getId().intValue();

      List list = new ArrayList();
      list = this.customerService.isRepeatSet();
      if ((list != null) && (list.size() > 0))
      {
        if (this.customerService.isRepeatUpdateCustomer(customer)) {
          request.setAttribute("repeat", Integer.valueOf(1));
          request.setAttribute("customer", customer);
          return preUpdateCustomer(request, response);
        }
      }

      customer.setUpdateCustomerDate(new Date());
      
      MultipartFile multipartFile = customer.getContents();
      if ((multipartFile != null) && (!multipartFile.isEmpty()) && 
        (multipartFile.getSize() > 10000000L)) {
        request.setAttribute("failResult", Integer.valueOf(3));
        request.setAttribute("customer", customer);
        return preUpdateCustomer(request, response);
      }

      String realPath = "";
      if ((multipartFile != null) && (!multipartFile.isEmpty())) {
        realPath = getServletContext().getRealPath("/");
      }
      
      result = this.customerService.updateCustomer(customer, realPath);
      if (result) success = 1;
    }
    return new ModelAndView(new RedirectView("./customerManage.do?action=preUpdateCustomer&result=" + success + "&id=" + id + "&sign=" + sign));
  }

  public ModelAndView discardCustomer(HttpServletRequest request, HttpServletResponse response)
  {
    String uri = "./customerManage.do?action=display";
    String sign = request.getParameter("sign");
    if ("11".equals(sign))
      uri = "./customerManage.do?action=display";
    else if ("12".equals(sign))
      uri = "./customerManage.do?action=deptCustomer";
    else if ("21".equals(sign))
      uri = "./contractCustomer.do?action=display";
    else if ("22".equals(sign))
      uri = "./contractCustomer.do?action=deptCustomer";
    else if ("31".equals(sign))
      uri = "./exceptionCustomer.do?action=display";
    else if ("41".equals(sign))
      uri = "./assignCustomer.do?action=display";
    else if ("51".equals(sign))
      uri = "./repeatCustomer.do?action=display";
    else if ("61".equals(sign)) {
      uri = "./customerCollect.do?action=display";
    }

    String viewType = request.getParameter("viewType");
    boolean result = false;
    int success = 0;
    String[] ids = request.getParameterValues("id");
    result = this.customerService.discardMyCustomers(ids);
    if (result) success = 1;
    return new ModelAndView(new RedirectView(uri + "&viewType=" + viewType + "&deleteResult=" + success));
  }

  public ModelAndView shareCustomer(HttpServletRequest request, HttpServletResponse response)
  {
    Map map = new HashMap();
    map.put("sign", request.getParameter("sign"));
    map.put("result", request.getParameter("result"));
    String customerId = request.getParameter("customerId");
    map.put("customerId", customerId);
    if (!StringUtils.isEmpty(customerId)) {
      map.put("customerShares", this.customerShareService.getActivityCustomerSharesByCustomerId(Integer.valueOf(Integer.parseInt(customerId))));
      map.put("customer", this.customerService.getCustomerById(Integer.valueOf(Integer.parseInt(customerId))));
    }
    return new ModelAndView(getShareCustomer(), map);
  }

  public ModelAndView preUpdateShareCustomer(HttpServletRequest request, HttpServletResponse response)
  {
    Map map = new HashMap();
    map.put("sign", request.getParameter("sign"));

    String customerId = request.getParameter("customerId");
    map.put("customerId", customerId);

    if (!StringUtils.isEmpty(customerId)) {
      List users = new ArrayList();
      users = this.userService.getActivityUsers();
      map.put("users", users);
    }
    return new ModelAndView(getUpdateShareCustomer(), map);
  }

  public ModelAndView updateShareCustomer(HttpServletRequest request, HttpServletResponse response, CustomerShare customerShare)
  {
    boolean result = false;
    int success = 0;
    String sign = request.getParameter("sign");

    if (customerShare != null) {
      result = this.customerShareService.insertCustomerShare(customerShare);
      if (result) success = 1;
    }
    return new ModelAndView(new RedirectView("./customerManage.do?action=shareCustomer&result=" + success + "&customerId=" + customerShare.getCustomerId() + "&sign=" + sign));
  }

  public ModelAndView deleteShareCustomer(HttpServletRequest request, HttpServletResponse response, CustomerShare customerShare)
  {
    boolean result = false;
    int success = 0;
    String sign = request.getParameter("sign");

    if (customerShare != null) {
      result = this.customerShareService.deleteCustomerShare(customerShare);
      if (result) success = 3;
    }
    return new ModelAndView(new RedirectView("./customerManage.do?action=shareCustomer&result=" + success + "&customerId=" + customerShare.getCustomerId() + "&sign=" + sign));
  }

  public ModelAndView customerDetail(HttpServletRequest request, HttpServletResponse response)
  {
    Map map = new HashMap();
    Integer userId = (Integer)request.getSession().getAttribute("userId");
    String customerId = request.getParameter("customerId");
    String sign = request.getParameter("sign");
    map.put("sign", sign);
    map.put("result", request.getParameter("result"));
    map.put("records", this.customerService.getCustomerInfoRecords());
    map.put("ranges", this.customerService.getCustomerDictionaryRanges());
    map.put("saleStages", this.saleStageSetService.getSaleStages());

    String realPath = getServletContext().getRealPath("/");
    if (!StringUtils.isEmpty(customerId)) {
      map.put("customer", this.customerService.getCustomerById2(Integer.valueOf(Integer.parseInt(customerId)), realPath, userId));
      map.put("linkmanRanges", this.linkmanService.getLinkmanDictionaryRanges());
      map.put("saleInfo", this.customerService.getCustomerSaleInfoById(Integer.valueOf(Integer.parseInt(customerId))));
      map.put("customerAddes", this.customerService.getCustomerAddedsById(realPath, Integer.parseInt(customerId)));

      CustomerLimitForm customerLimitForm = new CustomerLimitForm();
      customerLimitForm = this.customerService.getCustomerLimit(userId);
      if (this.assessmentTypeService.isExpUser(userId)) {
        map.put("isExpUser", "1");
      }
      map.put("customerLimitForm", customerLimitForm);
      map.put("discardLimitNum", this.customerService.getDiscardCustomerNum(userId));

      if ((!StringUtils.isEmpty(sign)) && ("11".equals(sign))) {
        this.customerService.updateViewCustomerDate(Integer.valueOf(Integer.parseInt(customerId)));
      }
    }

    return new ModelAndView(getCustomerDetail(), map);
  }

  public ModelAndView advancedQueryCustomer(HttpServletRequest request, HttpServletResponse response)
  {
    Map map = new HashMap();
    map.put("records", this.customerService.getCustomerInfoRecords());
    map.put("ranges", this.customerService.getCustomerDictionaryRanges());

    return new ModelAndView(getAdvancedQuery(), map);
  }

  public ModelAndView deptAdvancedQueryCustomer(HttpServletRequest request, HttpServletResponse response)
  {
    Map map = new HashMap();
    map.put("records", this.customerService.getCustomerInfoRecords());
    map.put("ranges", this.customerService.getCustomerDictionaryRanges());

    Integer userId = (Integer)request.getSession().getAttribute("userId");
    List users = new ArrayList();
    if (userId != null) {
      String deptIds = this.departmentService.getCurrentDeptIdAndSubDeptIdsByUserId(userId);
      users = this.userService.getActivityUsersByDeptIds(deptIds);
    }
    map.put("users", users);

    return new ModelAndView(getDeptAdvancedQuery(), map);
  }

  public ModelAndView customerUpdateHistory(HttpServletRequest request, HttpServletResponse response)
  {
    Map map = new HashMap();
    map.put("result", request.getParameter("result"));
    map.put("sign", request.getParameter("sign"));
    String customerId = request.getParameter("customerId");
    map.put("customerId", customerId);
    if (!StringUtils.isEmpty(customerId)) {
      Page page = new Page();
      page.getPageList(this.customerUpdateHistoryService.getPageCustomerUpdateHistorysCountByCustomerId(Integer.valueOf(Integer.parseInt(customerId))).intValue(), Integer.valueOf(5), request);

      map.put("customers", this.customerUpdateHistoryService.getPageCustomerUpdateHistorysByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), page));
    }

    return new ModelAndView(getCustomerUpdateHistory(), map);
  }

  public ModelAndView customerUpdateHistoryDetail(HttpServletRequest request, HttpServletResponse response)
  {
    Map map = new HashMap();
    String id = request.getParameter("id");
    if (!StringUtils.isEmpty(id)) {
      map.put("records", this.customerService.getCustomerInfoRecords());
      map.put("ranges", this.customerService.getCustomerDictionaryRanges());
      map.put("customer", this.customerUpdateHistoryService.getCustomerUpdateHistory(Integer.valueOf(Integer.parseInt(id))));
    }
    return new ModelAndView(getCustomerUpdateHistoryDetail(), map);
  }

  public ModelAndView restoreCustomerInfo(HttpServletRequest request, HttpServletResponse response)
  {
    Map map = new HashMap();
    String sign = request.getParameter("sign");
    String customerId = request.getParameter("customerId");

    boolean result = false;
    int success = 0;
    Integer userId = (Integer)request.getSession().getAttribute("userId");
    String id = request.getParameter("id");
    if ((!StringUtils.isEmpty(id)) && (userId != null)) {
      result = this.customerUpdateHistoryService.restoreCustomerInfo(Integer.valueOf(Integer.parseInt(id)), userId);
      if (result) success = 1;
    }
    return new ModelAndView(new RedirectView("./customerManage.do?action=customerUpdateHistory&sign=" + sign + "&customerId=" + customerId + "&result=" + success));
  }

  public ModelAndView viewSaleInfo(HttpServletRequest request, HttpServletResponse response)
  {
    Map model = new HashMap();
    model.put("sign", request.getParameter("sign"));
    String customerId = request.getParameter("customerId");
    model.put("customerId", customerId);
    if (!StringUtils.isEmpty(customerId)) {
      model.put("customer", this.customerService.getCustomerSaleInfoById(Integer.valueOf(Integer.parseInt(customerId))));
    }
    return new ModelAndView(getViewSaleInfo(), model);
  }
  public ModelAndView getDeptNameCustomer(HttpServletRequest request, HttpServletResponse response, QueryCustomer queryCustomer) {
    Integer userId = (Integer)request.getSession().getAttribute("userId");
    List saleStages = this.manageReportService.getSaleStages();
    List users = new ArrayList();
    if (userId != null) {
      String deptIds = this.departmentService.getCurrentDeptIdAndSubDeptIdsByUserId(userId);
      users = this.userService.getActivityUsersByDeptIds(deptIds);
    }

    Map model = new HashMap();
    String sFlag = request.getParameter("sFlag");
    String customerName2 = "客户名称";
    if ((!StringUtils.isEmpty(sFlag)) && ("1".equals(sFlag))) {
      customerName2 = request.getParameter("customerName2");
    }
    model.put("customerName2", customerName2);
    model.put("sFlag", sFlag);
    QueryCustomer qCustomer = null;
    if ((!StringUtils.isEmpty(sFlag)) && ("2".equals(sFlag))) {
      qCustomer = queryCustomer;
    }
    model.put("queryCustomer", qCustomer);

    if ((request.getParameter("see") != null) && (!request.getParameter("see").trim().equals("")) && (request.getParameter("customerId") != null)) {
      String customerId = request.getParameter("customerId");
      String sign = request.getParameter("sign");
      model.put("customerId", customerId);
      model.put("contracts", this.contractService.getContractByCustomerId(Integer.valueOf(Integer.parseInt(customerId))));
      model.put("result", request.getParameter("result"));
      model.put("records", this.customerService.getCustomerInfoRecords());
      model.put("ranges", this.customerService.getCustomerDictionaryRanges());
      model.put("saleStages", this.saleStageSetService.getSaleStages());

      model.put("saleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "0"));
      model.put("hisRootSaleRecords", this.saleRecordService.getCloseSaleRcordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId))));
      model.put("hisSaleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "1"));
      model.put("careSaleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "2"));
      model.put("hangupSaleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "3"));
      String realPath = getServletContext().getRealPath("/");
      if (!StringUtils.isEmpty(customerId)) {
        model.put("customer", this.customerService.getCustomerById2(Integer.valueOf(Integer.parseInt(customerId)), realPath, userId));
        model.put("linkmanRanges", this.linkmanService.getLinkmanDictionaryRanges());
        model.put("saleInfo", this.customerService.getCustomerSaleInfoById(Integer.valueOf(Integer.parseInt(customerId))));

        CustomerLimitForm customerLimitForm = new CustomerLimitForm();
        customerLimitForm = this.customerService.getCustomerLimit(userId);
        if (this.assessmentTypeService.isExpUser(userId)) {
          model.put("isExpUser", "1");
        }
        model.put("customerLimitForm", customerLimitForm);
        model.put("discardLimitNum", this.customerService.getDiscardCustomerNum(userId));

        if ((!StringUtils.isEmpty(sign)) && ("11".equals(sign))) {
          this.customerService.updateViewCustomerDate(Integer.valueOf(Integer.parseInt(customerId)));
        }
      }
    }
    model.put("users", users);
    model.put("saleStages", saleStages);
    Page page = new Page();
    page.getPageList(this.customerService.getDeptNameCustomerCount(userId, customerName2, qCustomer).intValue(), Integer.valueOf(10), request);
    model.put("customers", this.customerService.getDeptNameCustomer(userId, page, customerName2, qCustomer));
    return new ModelAndView(getDeptNameCustomer(), model);
  }

  public ModelAndView getOwnNameCustomer(HttpServletRequest request, HttpServletResponse response, QueryCustomer queryCustomer) {
    Integer userId = (Integer)request.getSession().getAttribute("userId");
    List saleStages = this.manageReportService.getSaleStages();
    Map model = new HashMap();
    String sFlag = request.getParameter("sFlag");
    String customerName2 = "客户名称";
    if ((!StringUtils.isEmpty(sFlag)) && ("1".equals(sFlag))) {
      customerName2 = request.getParameter("customerName2");
    }
    model.put("customerName2", customerName2);
    model.put("sFlag", sFlag);
    QueryCustomer qCustomer = null;
    if ((!StringUtils.isEmpty(sFlag)) && ("2".equals(sFlag))) {
      qCustomer = queryCustomer;
    }
    model.put("queryCustomer", qCustomer);
    if ((request.getParameter("see") != null) && (!request.getParameter("see").trim().equals("")) && (request.getParameter("customerId") != null)) {
      String customerId = request.getParameter("customerId");
      String sign = request.getParameter("sign");
      model.put("customerId", customerId);
      model.put("contracts", this.contractService.getContractByCustomerId(Integer.valueOf(Integer.parseInt(customerId))));
      model.put("result", request.getParameter("result"));
      model.put("records", this.customerService.getCustomerInfoRecords());
      model.put("ranges", this.customerService.getCustomerDictionaryRanges());
      model.put("saleStages", this.saleStageSetService.getSaleStages());

      model.put("saleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "0"));
      model.put("hisRootSaleRecords", this.saleRecordService.getCloseSaleRcordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId))));
      model.put("hisSaleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "1"));
      model.put("careSaleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "2"));
      model.put("hangupSaleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "3"));
      String realPath = getServletContext().getRealPath("/");
      if (!StringUtils.isEmpty(customerId)) {
        model.put("customer", this.customerService.getCustomerById2(Integer.valueOf(Integer.parseInt(customerId)), realPath, userId));
        model.put("linkmanRanges", this.linkmanService.getLinkmanDictionaryRanges());
        model.put("saleInfo", this.customerService.getCustomerSaleInfoById(Integer.valueOf(Integer.parseInt(customerId))));

        CustomerLimitForm customerLimitForm = new CustomerLimitForm();
        customerLimitForm = this.customerService.getCustomerLimit(userId);
        if (this.assessmentTypeService.isExpUser(userId)) {
          model.put("isExpUser", "1");
        }
        model.put("customerLimitForm", customerLimitForm);
        model.put("discardLimitNum", this.customerService.getDiscardCustomerNum(userId));

        if ((!StringUtils.isEmpty(sign)) && ("11".equals(sign))) {
          this.customerService.updateViewCustomerDate(Integer.valueOf(Integer.parseInt(customerId)));
        }
      }
    }
    model.put("saleStages", saleStages);
    Page page = new Page();
    page.getPageList(this.customerService.getOwnNameCustomerCount(userId, customerName2, qCustomer).intValue(), Integer.valueOf(10), request);
    model.put("customers", this.customerService.getOwnNameCustomer(userId, page, customerName2, qCustomer));
    return new ModelAndView(getOwnNameCustomer(), model);
  }

  public ModelAndView myShareCustomer(HttpServletRequest request, HttpServletResponse response, QueryCustomer queryCustomer) {
    Integer userId = (Integer)request.getSession().getAttribute("userId");
    List saleStages = this.manageReportService.getSaleStages();
    List users = new ArrayList();
    if (userId != null) {
      String deptIds = this.departmentService.getCurrentDeptIdAndSubDeptIdsByUserId(userId);
      users = this.userService.getActivityUsersByDeptIds(deptIds);
    }
    Map model = new HashMap();
    String sFlag = request.getParameter("sFlag");
    String customerName2 = "客户名称";
    if ((!StringUtils.isEmpty(sFlag)) && ("1".equals(sFlag))) {
      customerName2 = request.getParameter("customerName2");
    }
    model.put("customerName2", customerName2);
    model.put("sFlag", sFlag);
    QueryCustomer qCustomer = null;
    if ((!StringUtils.isEmpty(sFlag)) && ("2".equals(sFlag))) {
      qCustomer = queryCustomer;
    }
    model.put("queryCustomer", qCustomer);
    if ((request.getParameter("see") != null) && (!request.getParameter("see").trim().equals("")) && (request.getParameter("customerId") != null)) {
      String customerId = request.getParameter("customerId");
      String sign = request.getParameter("sign");
      model.put("customerId", customerId);
      model.put("contracts", this.contractService.getContractByCustomerId(Integer.valueOf(Integer.parseInt(customerId))));
      model.put("result", request.getParameter("result"));
      model.put("records", this.customerService.getCustomerInfoRecords());
      model.put("ranges", this.customerService.getCustomerDictionaryRanges());
      model.put("saleStages", this.saleStageSetService.getSaleStages());

      model.put("saleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "0"));
      model.put("hisRootSaleRecords", this.saleRecordService.getCloseSaleRcordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId))));
      model.put("hisSaleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "1"));
      model.put("careSaleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "2"));
      model.put("hangupSaleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "3"));
      String realPath = getServletContext().getRealPath("/");
      if (!StringUtils.isEmpty(customerId)) {
        model.put("customer", this.customerService.getCustomerById2(Integer.valueOf(Integer.parseInt(customerId)), realPath, userId));
        model.put("linkmanRanges", this.linkmanService.getLinkmanDictionaryRanges());
        model.put("saleInfo", this.customerService.getCustomerSaleInfoById(Integer.valueOf(Integer.parseInt(customerId))));

        CustomerLimitForm customerLimitForm = new CustomerLimitForm();
        customerLimitForm = this.customerService.getCustomerLimit(userId);
        if (this.assessmentTypeService.isExpUser(userId)) {
          model.put("isExpUser", "1");
        }
        model.put("customerLimitForm", customerLimitForm);
        model.put("discardLimitNum", this.customerService.getDiscardCustomerNum(userId));

        if ((!StringUtils.isEmpty(sign)) && ("11".equals(sign))) {
          this.customerService.updateViewCustomerDate(Integer.valueOf(Integer.parseInt(customerId)));
        }
      }
    }
    model.put("users", users);
    model.put("saleStages", saleStages);
    Page page = new Page();
    page.getPageList(this.customerService.getMyShareCustomerCount(userId, customerName2, qCustomer).intValue(), Integer.valueOf(10), request);
    model.put("customers", this.customerService.getMyShareCustomer(userId, page, customerName2, qCustomer));
    return new ModelAndView(getMyShareCustomer(), model);
  }

  public ModelAndView nearViewCustomer(HttpServletRequest request, HttpServletResponse response, QueryCustomer queryCustomer) {
    Integer userId = (Integer)request.getSession().getAttribute("userId");
    List saleStages = this.manageReportService.getSaleStages();
    Map model = new HashMap();
    String sFlag = request.getParameter("sFlag");
    String customerName2 = "客户名称";
    if ((!StringUtils.isEmpty(sFlag)) && ("1".equals(sFlag))) {
      customerName2 = request.getParameter("customerName2");
    }
    model.put("customerName2", customerName2);
    model.put("sFlag", sFlag);
    QueryCustomer qCustomer = null;
    if ((!StringUtils.isEmpty(sFlag)) && ("2".equals(sFlag))) {
      qCustomer = queryCustomer;
    }
    model.put("queryCustomer", qCustomer);
    if ((request.getParameter("see") != null) && (!request.getParameter("see").trim().equals("")) && (request.getParameter("customerId") != null)) {
      String customerId = request.getParameter("customerId");
      String sign = request.getParameter("sign");
      model.put("customerId", customerId);
      model.put("contracts", this.contractService.getContractByCustomerId(Integer.valueOf(Integer.parseInt(customerId))));
      model.put("result", request.getParameter("result"));
      model.put("records", this.customerService.getCustomerInfoRecords());
      model.put("ranges", this.customerService.getCustomerDictionaryRanges());
      model.put("saleStages", this.saleStageSetService.getSaleStages());

      model.put("saleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "0"));
      model.put("hisRootSaleRecords", this.saleRecordService.getCloseSaleRcordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId))));
      model.put("hisSaleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "1"));
      model.put("careSaleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "2"));
      model.put("hangupSaleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "3"));
      String realPath = getServletContext().getRealPath("/");
      if (!StringUtils.isEmpty(customerId)) {
        model.put("customer", this.customerService.getCustomerById2(Integer.valueOf(Integer.parseInt(customerId)), realPath, userId));
        model.put("linkmanRanges", this.linkmanService.getLinkmanDictionaryRanges());
        model.put("saleInfo", this.customerService.getCustomerSaleInfoById(Integer.valueOf(Integer.parseInt(customerId))));

        CustomerLimitForm customerLimitForm = new CustomerLimitForm();
        customerLimitForm = this.customerService.getCustomerLimit(userId);
        if (this.assessmentTypeService.isExpUser(userId)) {
          model.put("isExpUser", "1");
        }
        model.put("customerLimitForm", customerLimitForm);
        model.put("discardLimitNum", this.customerService.getDiscardCustomerNum(userId));

        if ((!StringUtils.isEmpty(sign)) && ("11".equals(sign))) {
          this.customerService.updateViewCustomerDate(Integer.valueOf(Integer.parseInt(customerId)));
        }
      }
    }
    model.put("saleStages", saleStages);
    Page page = new Page();
    page.getPageList(this.customerService.getNearViewCustomersCount(userId, customerName2, qCustomer).intValue(), Integer.valueOf(10), request);
    model.put("customers", this.customerService.getNearViewCustomers(userId, page, customerName2, qCustomer));
    return new ModelAndView(getNearViewCustomer(), model);
  }

  public ModelAndView nearUpdatedCustomer(HttpServletRequest request, HttpServletResponse response, QueryCustomer queryCustomer) {
    Integer userId = (Integer)request.getSession().getAttribute("userId");
    List saleStages = this.manageReportService.getSaleStages();
    Map model = new HashMap();
    String sFlag = request.getParameter("sFlag");
    String customerName2 = "客户名称";
    if ((!StringUtils.isEmpty(sFlag)) && ("1".equals(sFlag))) {
      customerName2 = request.getParameter("customerName2");
    }
    model.put("customerName2", customerName2);
    model.put("sFlag", sFlag);
    QueryCustomer qCustomer = null;
    if ((!StringUtils.isEmpty(sFlag)) && ("2".equals(sFlag))) {
      qCustomer = queryCustomer;
    }
    model.put("queryCustomer", qCustomer);
    if ((request.getParameter("see") != null) && (!request.getParameter("see").trim().equals("")) && (request.getParameter("customerId") != null)) {
      String customerId = request.getParameter("customerId");
      String sign = request.getParameter("sign");
      model.put("customerId", customerId);
      model.put("contracts", this.contractService.getContractByCustomerId(Integer.valueOf(Integer.parseInt(customerId))));
      model.put("result", request.getParameter("result"));
      model.put("records", this.customerService.getCustomerInfoRecords());
      model.put("ranges", this.customerService.getCustomerDictionaryRanges());
      model.put("saleStages", this.saleStageSetService.getSaleStages());

      model.put("saleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "0"));
      model.put("hisRootSaleRecords", this.saleRecordService.getCloseSaleRcordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId))));
      model.put("hisSaleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "1"));
      model.put("careSaleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "2"));
      model.put("hangupSaleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "3"));
      String realPath = getServletContext().getRealPath("/");
      if (!StringUtils.isEmpty(customerId)) {
        model.put("customer", this.customerService.getCustomerById2(Integer.valueOf(Integer.parseInt(customerId)), realPath, userId));
        model.put("linkmanRanges", this.linkmanService.getLinkmanDictionaryRanges());
        model.put("saleInfo", this.customerService.getCustomerSaleInfoById(Integer.valueOf(Integer.parseInt(customerId))));

        CustomerLimitForm customerLimitForm = new CustomerLimitForm();
        customerLimitForm = this.customerService.getCustomerLimit(userId);
        if (this.assessmentTypeService.isExpUser(userId)) {
          model.put("isExpUser", "1");
        }
        model.put("customerLimitForm", customerLimitForm);
        model.put("discardLimitNum", this.customerService.getDiscardCustomerNum(userId));

        if ((!StringUtils.isEmpty(sign)) && ("11".equals(sign))) {
          this.customerService.updateViewCustomerDate(Integer.valueOf(Integer.parseInt(customerId)));
        }
      }
    }
    model.put("saleStages", saleStages);
    Page page = new Page();
    page.getPageList(this.customerService.getNearUpdatedCustomerCount(userId, customerName2, qCustomer).intValue(), Integer.valueOf(10), request);
    model.put("customers", this.customerService.getNearUpdatedCustomer(userId, page, customerName2, qCustomer));
    return new ModelAndView(getNearUpdatedCustomer(), model);
  }

  public ModelAndView deptSaleRecordCustomer(HttpServletRequest request, HttpServletResponse response, QueryCustomer queryCustomer) {
    Integer userId = (Integer)request.getSession().getAttribute("userId");
    List saleStages = this.manageReportService.getSaleStages();
    List users = new ArrayList();
    if (userId != null) {
      String deptIds = this.departmentService.getCurrentDeptIdAndSubDeptIdsByUserId(userId);
      users = this.userService.getActivityUsersByDeptIds(deptIds);
    }
    Map model = new HashMap();
    String sFlag = request.getParameter("sFlag");
    String customerName2 = "客户名称";
    if ((!StringUtils.isEmpty(sFlag)) && ("1".equals(sFlag))) {
      customerName2 = request.getParameter("customerName2");
    }
    model.put("customerName2", customerName2);
    model.put("sFlag", sFlag);
    QueryCustomer qCustomer = null;
    if ((!StringUtils.isEmpty(sFlag)) && ("2".equals(sFlag))) {
      qCustomer = queryCustomer;
    }
    model.put("queryCustomer", qCustomer);
    if ((request.getParameter("see") != null) && (!request.getParameter("see").trim().equals("")) && (request.getParameter("customerId") != null)) {
      String customerId = request.getParameter("customerId");
      String sign = request.getParameter("sign");
      model.put("customerId", customerId);
      model.put("contracts", this.contractService.getContractByCustomerId(Integer.valueOf(Integer.parseInt(customerId))));
      model.put("result", request.getParameter("result"));
      model.put("records", this.customerService.getCustomerInfoRecords());
      model.put("ranges", this.customerService.getCustomerDictionaryRanges());
      model.put("saleStages", this.saleStageSetService.getSaleStages());

      model.put("saleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "0"));
      model.put("hisRootSaleRecords", this.saleRecordService.getCloseSaleRcordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId))));
      model.put("hisSaleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "1"));
      model.put("careSaleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "2"));
      model.put("hangupSaleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "3"));
      String realPath = getServletContext().getRealPath("/");
      if (!StringUtils.isEmpty(customerId)) {
        model.put("customer", this.customerService.getCustomerById2(Integer.valueOf(Integer.parseInt(customerId)), realPath, userId));
        model.put("linkmanRanges", this.linkmanService.getLinkmanDictionaryRanges());
        model.put("saleInfo", this.customerService.getCustomerSaleInfoById(Integer.valueOf(Integer.parseInt(customerId))));

        CustomerLimitForm customerLimitForm = new CustomerLimitForm();
        customerLimitForm = this.customerService.getCustomerLimit(userId);
        if (this.assessmentTypeService.isExpUser(userId)) {
          model.put("isExpUser", "1");
        }
        model.put("customerLimitForm", customerLimitForm);
        model.put("discardLimitNum", this.customerService.getDiscardCustomerNum(userId));

        if ((!StringUtils.isEmpty(sign)) && ("11".equals(sign))) {
          this.customerService.updateViewCustomerDate(Integer.valueOf(Integer.parseInt(customerId)));
        }
      }
    }
    model.put("users", users);
    model.put("saleStages", saleStages);
    Page page = new Page();
    page.getPageList(this.customerService.getDeptSaleRecordCustomerCount(userId, customerName2, qCustomer).intValue(), Integer.valueOf(10), request);
    model.put("customers", this.customerService.getDeptSaleRecordCustomer(userId, page, customerName2, qCustomer));
    return new ModelAndView(getDeptSaleRecordCustomer(), model);
  }

  public ModelAndView deptSucceedContract(HttpServletRequest request, HttpServletResponse response, QueryCustomer queryCustomer) {
    Integer userId = (Integer)request.getSession().getAttribute("userId");
    List saleStages = this.manageReportService.getSaleStages();
    List users = new ArrayList();
    if (userId != null) {
      String deptIds = this.departmentService.getCurrentDeptIdAndSubDeptIdsByUserId(userId);
      users = this.userService.getActivityUsersByDeptIds(deptIds);
    }
    Map model = new HashMap();
    String sFlag = request.getParameter("sFlag");
    String customerName2 = "客户名称";
    if ((!StringUtils.isEmpty(sFlag)) && ("1".equals(sFlag))) {
      customerName2 = request.getParameter("customerName2");
    }
    model.put("customerName2", customerName2);
    model.put("sFlag", sFlag);
    QueryCustomer qCustomer = null;
    if ((!StringUtils.isEmpty(sFlag)) && ("2".equals(sFlag))) {
      qCustomer = queryCustomer;
    }
    model.put("queryCustomer", qCustomer);
    if ((request.getParameter("see") != null) && (!request.getParameter("see").trim().equals("")) && (request.getParameter("customerId") != null)) {
      String customerId = request.getParameter("customerId");
      String sign = request.getParameter("sign");
      model.put("customerId", customerId);
      model.put("contracts", this.contractService.getContractByCustomerId(Integer.valueOf(Integer.parseInt(customerId))));
      model.put("result", request.getParameter("result"));
      model.put("records", this.customerService.getCustomerInfoRecords());
      model.put("ranges", this.customerService.getCustomerDictionaryRanges());
      model.put("saleStages", this.saleStageSetService.getSaleStages());

      model.put("saleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "0"));
      model.put("hisRootSaleRecords", this.saleRecordService.getCloseSaleRcordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId))));
      model.put("hisSaleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "1"));
      model.put("careSaleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "2"));
      model.put("hangupSaleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "3"));
      String realPath = getServletContext().getRealPath("/");
      if (!StringUtils.isEmpty(customerId)) {
        model.put("customer", this.customerService.getCustomerById2(Integer.valueOf(Integer.parseInt(customerId)), realPath, userId));
        model.put("linkmanRanges", this.linkmanService.getLinkmanDictionaryRanges());
        model.put("saleInfo", this.customerService.getCustomerSaleInfoById(Integer.valueOf(Integer.parseInt(customerId))));

        CustomerLimitForm customerLimitForm = new CustomerLimitForm();
        customerLimitForm = this.customerService.getCustomerLimit(userId);
        if (this.assessmentTypeService.isExpUser(userId)) {
          model.put("isExpUser", "1");
        }
        model.put("customerLimitForm", customerLimitForm);
        model.put("discardLimitNum", this.customerService.getDiscardCustomerNum(userId));

        if ((!StringUtils.isEmpty(sign)) && ("11".equals(sign))) {
          this.customerService.updateViewCustomerDate(Integer.valueOf(Integer.parseInt(customerId)));
        }
      }
    }
    model.put("users", users);
    model.put("saleStages", saleStages);
    Page page = new Page();
    page.getPageList(this.customerService.getDeptSucceedContractCount(userId, customerName2, qCustomer).intValue(), Integer.valueOf(10), request);
    model.put("customers", this.customerService.getDeptSucceedContract(userId, page, customerName2, qCustomer));
    return new ModelAndView(getDeptSucceedContract(), model);
  }
  public ModelAndView mySucceedContract(HttpServletRequest request, HttpServletResponse response, QueryCustomer queryCustomer) {
    Integer userId = (Integer)request.getSession().getAttribute("userId");
    Map model = new HashMap();
    String sFlag = request.getParameter("sFlag");
    String customerName2 = "客户名称";
    if ((!StringUtils.isEmpty(sFlag)) && ("1".equals(sFlag))) {
      customerName2 = request.getParameter("customerName2");
    }
    model.put("customerName2", customerName2);
    model.put("sFlag", sFlag);
    QueryCustomer qCustomer = null;
    if ((!StringUtils.isEmpty(sFlag)) && ("2".equals(sFlag))) {
      qCustomer = queryCustomer;
    }
    model.put("queryCustomer", qCustomer);
    if ((request.getParameter("see") != null) && (!request.getParameter("see").trim().equals("")) && (request.getParameter("customerId") != null)) {
      String customerId = request.getParameter("customerId");
      String sign = request.getParameter("sign");
      model.put("customerId", customerId);
      model.put("contracts", this.contractService.getContractByCustomerId(Integer.valueOf(Integer.parseInt(customerId))));
      model.put("result", request.getParameter("result"));
      model.put("records", this.customerService.getCustomerInfoRecords());
      model.put("ranges", this.customerService.getCustomerDictionaryRanges());
      model.put("saleStages", this.saleStageSetService.getSaleStages());

      model.put("saleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "0"));
      model.put("hisRootSaleRecords", this.saleRecordService.getCloseSaleRcordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId))));
      model.put("hisSaleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "1"));
      model.put("careSaleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "2"));
      model.put("hangupSaleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "3"));
      String realPath = getServletContext().getRealPath("/");
      if (!StringUtils.isEmpty(customerId)) {
        model.put("customer", this.customerService.getCustomerById2(Integer.valueOf(Integer.parseInt(customerId)), realPath, userId));
        model.put("linkmanRanges", this.linkmanService.getLinkmanDictionaryRanges());
        model.put("saleInfo", this.customerService.getCustomerSaleInfoById(Integer.valueOf(Integer.parseInt(customerId))));

        CustomerLimitForm customerLimitForm = new CustomerLimitForm();
        customerLimitForm = this.customerService.getCustomerLimit(userId);
        if (this.assessmentTypeService.isExpUser(userId)) {
          model.put("isExpUser", "1");
        }
        model.put("customerLimitForm", customerLimitForm);
        model.put("discardLimitNum", this.customerService.getDiscardCustomerNum(userId));

        if ((!StringUtils.isEmpty(sign)) && ("11".equals(sign))) {
          this.customerService.updateViewCustomerDate(Integer.valueOf(Integer.parseInt(customerId)));
        }
      }
    }
    Page page = new Page();
    page.getPageList(this.customerService.getMySucceedContractCount(userId, customerName2, qCustomer).intValue(), Integer.valueOf(10), request);
    model.put("customers", this.customerService.getMySucceedContract(userId, page, customerName2, qCustomer));
    return new ModelAndView(getMySucceedContract(), model);
  }

  public ModelAndView deptHangupBusinessOpportunity(HttpServletRequest request, HttpServletResponse response, QueryCustomer queryCustomer) {
    Integer userId = (Integer)request.getSession().getAttribute("userId");
    List saleStages = this.manageReportService.getSaleStages();
    List users = new ArrayList();
    if (userId != null) {
      String deptIds = this.departmentService.getCurrentDeptIdAndSubDeptIdsByUserId(userId);
      users = this.userService.getActivityUsersByDeptIds(deptIds);
    }
    Map model = new HashMap();
    String sFlag = request.getParameter("sFlag");
    String customerName2 = "客户名称";
    if ((!StringUtils.isEmpty(sFlag)) && ("1".equals(sFlag))) {
      customerName2 = request.getParameter("customerName2");
    }
    model.put("customerName2", customerName2);
    model.put("sFlag", sFlag);
    QueryCustomer qCustomer = null;
    if ((!StringUtils.isEmpty(sFlag)) && ("2".equals(sFlag))) {
      qCustomer = queryCustomer;
    }
    model.put("queryCustomer", qCustomer);
    if ((request.getParameter("see") != null) && (!request.getParameter("see").trim().equals("")) && (request.getParameter("customerId") != null)) {
      String customerId = request.getParameter("customerId");
      String sign = request.getParameter("sign");
      model.put("customerId", customerId);
      model.put("contracts", this.contractService.getContractByCustomerId(Integer.valueOf(Integer.parseInt(customerId))));
      model.put("result", request.getParameter("result"));
      model.put("records", this.customerService.getCustomerInfoRecords());
      model.put("ranges", this.customerService.getCustomerDictionaryRanges());
      model.put("saleStages", this.saleStageSetService.getSaleStages());

      model.put("saleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "0"));
      model.put("hisRootSaleRecords", this.saleRecordService.getCloseSaleRcordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId))));
      model.put("hisSaleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "1"));
      model.put("careSaleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "2"));
      model.put("hangupSaleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "3"));
      String realPath = getServletContext().getRealPath("/");
      if (!StringUtils.isEmpty(customerId)) {
        model.put("customer", this.customerService.getCustomerById2(Integer.valueOf(Integer.parseInt(customerId)), realPath, userId));
        model.put("linkmanRanges", this.linkmanService.getLinkmanDictionaryRanges());
        model.put("saleInfo", this.customerService.getCustomerSaleInfoById(Integer.valueOf(Integer.parseInt(customerId))));

        CustomerLimitForm customerLimitForm = new CustomerLimitForm();
        customerLimitForm = this.customerService.getCustomerLimit(userId);
        if (this.assessmentTypeService.isExpUser(userId)) {
          model.put("isExpUser", "1");
        }
        model.put("customerLimitForm", customerLimitForm);
        model.put("discardLimitNum", this.customerService.getDiscardCustomerNum(userId));

        if ((!StringUtils.isEmpty(sign)) && ("11".equals(sign))) {
          this.customerService.updateViewCustomerDate(Integer.valueOf(Integer.parseInt(customerId)));
        }
      }
    }
    model.put("users", users);
    model.put("saleStages", saleStages);
    Page page = new Page();
    page.getPageList(this.customerService.getDeptHangupBusinessOpportunityCount(userId, customerName2, qCustomer).intValue(), Integer.valueOf(10), request);
    model.put("customers", this.customerService.getDeptHangupBusinessOpportunity(userId, page, customerName2, qCustomer));
    return new ModelAndView(getDeptHangupBusinessOpportunity(), model);
  }
  public ModelAndView myHangupBusinessOpportunity(HttpServletRequest request, HttpServletResponse response, QueryCustomer queryCustomer) {
    Integer userId = (Integer)request.getSession().getAttribute("userId");
    List saleStages = this.manageReportService.getSaleStages();
    Map model = new HashMap();
    String sFlag = request.getParameter("sFlag");
    String customerName2 = "客户名称";
    if ((!StringUtils.isEmpty(sFlag)) && ("1".equals(sFlag))) {
      customerName2 = request.getParameter("customerName2");
    }
    model.put("customerName2", customerName2);
    model.put("sFlag", sFlag);
    QueryCustomer qCustomer = null;
    if ((!StringUtils.isEmpty(sFlag)) && ("2".equals(sFlag))) {
      qCustomer = queryCustomer;
    }
    model.put("queryCustomer", qCustomer);
    if ((request.getParameter("see") != null) && (!request.getParameter("see").trim().equals("")) && (request.getParameter("customerId") != null)) {
      String customerId = request.getParameter("customerId");
      String sign = request.getParameter("sign");
      model.put("customerId", customerId);
      model.put("contracts", this.contractService.getContractByCustomerId(Integer.valueOf(Integer.parseInt(customerId))));
      model.put("result", request.getParameter("result"));
      model.put("records", this.customerService.getCustomerInfoRecords());
      model.put("ranges", this.customerService.getCustomerDictionaryRanges());
      model.put("saleStages", this.saleStageSetService.getSaleStages());

      model.put("saleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "0"));
      model.put("hisRootSaleRecords", this.saleRecordService.getCloseSaleRcordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId))));
      model.put("hisSaleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "1"));
      model.put("careSaleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "2"));
      model.put("hangupSaleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "3"));
      String realPath = getServletContext().getRealPath("/");
      if (!StringUtils.isEmpty(customerId)) {
        model.put("customer", this.customerService.getCustomerById2(Integer.valueOf(Integer.parseInt(customerId)), realPath, userId));
        model.put("linkmanRanges", this.linkmanService.getLinkmanDictionaryRanges());
        model.put("saleInfo", this.customerService.getCustomerSaleInfoById(Integer.valueOf(Integer.parseInt(customerId))));

        CustomerLimitForm customerLimitForm = new CustomerLimitForm();
        customerLimitForm = this.customerService.getCustomerLimit(userId);
        if (this.assessmentTypeService.isExpUser(userId)) {
          model.put("isExpUser", "1");
        }
        model.put("customerLimitForm", customerLimitForm);
        model.put("discardLimitNum", this.customerService.getDiscardCustomerNum(userId));

        if ((!StringUtils.isEmpty(sign)) && ("11".equals(sign))) {
          this.customerService.updateViewCustomerDate(Integer.valueOf(Integer.parseInt(customerId)));
        }
      }
    }
    model.put("saleStages", saleStages);
    Page page = new Page();
    page.getPageList(this.customerService.getMyHangupBusinessOpportunityCount(userId, customerName2, qCustomer).intValue(), Integer.valueOf(10), request);
    model.put("customers", this.customerService.getMyHangupBusinessOpportunity(userId, page, customerName2, qCustomer));
    return new ModelAndView(getMyHangupBusinessOpportunity(), model);
  }
  public ModelAndView deptGiveupBusinessOpportunity(HttpServletRequest request, HttpServletResponse response, QueryCustomer queryCustomer) {
    Integer userId = (Integer)request.getSession().getAttribute("userId");
    List saleStages = this.manageReportService.getSaleStages();
    List users = new ArrayList();
    if (userId != null) {
      String deptIds = this.departmentService.getCurrentDeptIdAndSubDeptIdsByUserId(userId);
      users = this.userService.getActivityUsersByDeptIds(deptIds);
    }
    Map model = new HashMap();
    String sFlag = request.getParameter("sFlag");
    String customerName2 = "客户名称";
    if ((!StringUtils.isEmpty(sFlag)) && ("1".equals(sFlag))) {
      customerName2 = request.getParameter("customerName2");
    }
    model.put("customerName2", customerName2);
    model.put("sFlag", sFlag);
    QueryCustomer qCustomer = null;
    if ((!StringUtils.isEmpty(sFlag)) && ("2".equals(sFlag))) {
      qCustomer = queryCustomer;
    }
    model.put("queryCustomer", qCustomer);
    if ((request.getParameter("see") != null) && (!request.getParameter("see").trim().equals("")) && (request.getParameter("customerId") != null)) {
      String customerId = request.getParameter("customerId");
      String sign = request.getParameter("sign");
      model.put("customerId", customerId);
      model.put("contracts", this.contractService.getContractByCustomerId(Integer.valueOf(Integer.parseInt(customerId))));
      model.put("result", request.getParameter("result"));
      model.put("records", this.customerService.getCustomerInfoRecords());
      model.put("ranges", this.customerService.getCustomerDictionaryRanges());
      model.put("saleStages", this.saleStageSetService.getSaleStages());

      model.put("saleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "0"));
      model.put("hisRootSaleRecords", this.saleRecordService.getCloseSaleRcordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId))));
      model.put("hisSaleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "1"));
      model.put("careSaleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "2"));
      model.put("hangupSaleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "3"));
      String realPath = getServletContext().getRealPath("/");
      if (!StringUtils.isEmpty(customerId)) {
        model.put("customer", this.customerService.getCustomerById2(Integer.valueOf(Integer.parseInt(customerId)), realPath, userId));
        model.put("linkmanRanges", this.linkmanService.getLinkmanDictionaryRanges());
        model.put("saleInfo", this.customerService.getCustomerSaleInfoById(Integer.valueOf(Integer.parseInt(customerId))));

        CustomerLimitForm customerLimitForm = new CustomerLimitForm();
        customerLimitForm = this.customerService.getCustomerLimit(userId);
        if (this.assessmentTypeService.isExpUser(userId)) {
          model.put("isExpUser", "1");
        }
        model.put("customerLimitForm", customerLimitForm);
        model.put("discardLimitNum", this.customerService.getDiscardCustomerNum(userId));

        if ((!StringUtils.isEmpty(sign)) && ("11".equals(sign))) {
          this.customerService.updateViewCustomerDate(Integer.valueOf(Integer.parseInt(customerId)));
        }
      }
    }
    model.put("users", users);
    model.put("saleStages", saleStages);
    Page page = new Page();
    page.getPageList(this.customerService.getDeptGiveupBusinessOpportunityCount(userId, customerName2, qCustomer).intValue(), Integer.valueOf(10), request);
    model.put("customers", this.customerService.getDeptGiveupBusinessOpportunity(userId, page, customerName2, qCustomer));
    return new ModelAndView(getDeptGiveupBusinessOpportunity(), model);
  }
  public ModelAndView myGiveupBusinessOpportunity(HttpServletRequest request, HttpServletResponse response, QueryCustomer queryCustomer) {
    Integer userId = (Integer)request.getSession().getAttribute("userId");
    Map model = new HashMap();
    String sFlag = request.getParameter("sFlag");
    String customerName2 = "客户名称";
    if ((!StringUtils.isEmpty(sFlag)) && ("1".equals(sFlag))) {
      customerName2 = request.getParameter("customerName2");
    }
    model.put("customerName2", customerName2);
    model.put("sFlag", sFlag);
    QueryCustomer qCustomer = null;
    if ((!StringUtils.isEmpty(sFlag)) && ("2".equals(sFlag))) {
      qCustomer = queryCustomer;
    }
    model.put("queryCustomer", qCustomer);
    if ((request.getParameter("see") != null) && (!request.getParameter("see").trim().equals("")) && (request.getParameter("customerId") != null)) {
      String customerId = request.getParameter("customerId");
      String sign = request.getParameter("sign");
      model.put("customerId", customerId);
      model.put("contracts", this.contractService.getContractByCustomerId(Integer.valueOf(Integer.parseInt(customerId))));
      model.put("result", request.getParameter("result"));
      model.put("records", this.customerService.getCustomerInfoRecords());
      model.put("ranges", this.customerService.getCustomerDictionaryRanges());
      model.put("saleStages", this.saleStageSetService.getSaleStages());

      model.put("saleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "0"));
      model.put("hisRootSaleRecords", this.saleRecordService.getCloseSaleRcordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId))));
      model.put("hisSaleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "1"));
      model.put("careSaleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "2"));
      model.put("hangupSaleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "3"));
      String realPath = getServletContext().getRealPath("/");
      if (!StringUtils.isEmpty(customerId)) {
        model.put("customer", this.customerService.getCustomerById2(Integer.valueOf(Integer.parseInt(customerId)), realPath, userId));
        model.put("linkmanRanges", this.linkmanService.getLinkmanDictionaryRanges());
        model.put("saleInfo", this.customerService.getCustomerSaleInfoById(Integer.valueOf(Integer.parseInt(customerId))));

        CustomerLimitForm customerLimitForm = new CustomerLimitForm();
        customerLimitForm = this.customerService.getCustomerLimit(userId);
        if (this.assessmentTypeService.isExpUser(userId)) {
          model.put("isExpUser", "1");
        }
        model.put("customerLimitForm", customerLimitForm);
        model.put("discardLimitNum", this.customerService.getDiscardCustomerNum(userId));

        if ((!StringUtils.isEmpty(sign)) && ("11".equals(sign))) {
          this.customerService.updateViewCustomerDate(Integer.valueOf(Integer.parseInt(customerId)));
        }
      }
    }
    Page page = new Page();
    page.getPageList(this.customerService.getMyGiveupBusinessOpportunityCount(userId, customerName2, qCustomer).intValue(), Integer.valueOf(10), request);
    model.put("customers", this.customerService.getMyGiveupBusinessOpportunity(userId, page, customerName2, qCustomer));
    return new ModelAndView(getMyGiveupBusinessOpportunity(), model);
  }
  public ModelAndView nearChangedBusinessOpportunity(HttpServletRequest request, HttpServletResponse response, QueryCustomer queryCustomer) {
    Integer userId = (Integer)request.getSession().getAttribute("userId");
    List saleStages = this.manageReportService.getSaleStages();
    Map model = new HashMap();
    String sFlag = request.getParameter("sFlag");
    String customerName2 = "客户名称";
    if ((!StringUtils.isEmpty(sFlag)) && ("1".equals(sFlag))) {
      customerName2 = request.getParameter("customerName2");
    }
    model.put("customerName2", customerName2);
    model.put("sFlag", sFlag);
    QueryCustomer qCustomer = null;
    if ((!StringUtils.isEmpty(sFlag)) && ("2".equals(sFlag))) {
      qCustomer = queryCustomer;
    }
    model.put("queryCustomer", qCustomer);
    if ((request.getParameter("see") != null) && (!request.getParameter("see").trim().equals("")) && (request.getParameter("customerId") != null)) {
      String customerId = request.getParameter("customerId");
      String sign = request.getParameter("sign");
      model.put("customerId", customerId);
      model.put("contracts", this.contractService.getContractByCustomerId(Integer.valueOf(Integer.parseInt(customerId))));
      model.put("result", request.getParameter("result"));
      model.put("records", this.customerService.getCustomerInfoRecords());
      model.put("ranges", this.customerService.getCustomerDictionaryRanges());
      model.put("saleStages", this.saleStageSetService.getSaleStages());

      model.put("saleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "0"));
      model.put("hisRootSaleRecords", this.saleRecordService.getCloseSaleRcordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId))));
      model.put("hisSaleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "1"));
      model.put("careSaleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "2"));
      model.put("hangupSaleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "3"));
      String realPath = getServletContext().getRealPath("/");
      if (!StringUtils.isEmpty(customerId)) {
        model.put("customer", this.customerService.getCustomerById2(Integer.valueOf(Integer.parseInt(customerId)), realPath, userId));
        model.put("linkmanRanges", this.linkmanService.getLinkmanDictionaryRanges());
        model.put("saleInfo", this.customerService.getCustomerSaleInfoById(Integer.valueOf(Integer.parseInt(customerId))));

        CustomerLimitForm customerLimitForm = new CustomerLimitForm();
        customerLimitForm = this.customerService.getCustomerLimit(userId);
        if (this.assessmentTypeService.isExpUser(userId)) {
          model.put("isExpUser", "1");
        }
        model.put("customerLimitForm", customerLimitForm);
        model.put("discardLimitNum", this.customerService.getDiscardCustomerNum(userId));

        if ((!StringUtils.isEmpty(sign)) && ("11".equals(sign))) {
          this.customerService.updateViewCustomerDate(Integer.valueOf(Integer.parseInt(customerId)));
        }
      }
    }
    model.put("saleStages", saleStages);
    Page page = new Page();
    page.getPageList(this.customerService.getNearChangedBusinessOpportunityCount(userId, customerName2, qCustomer).intValue(), Integer.valueOf(10), request);
    model.put("customers", this.customerService.getNearChangedBusinessOpportunity(userId, page, customerName2, qCustomer));
    return new ModelAndView(getNearChangedBusinessOpportunity(), model);
  }
  public ModelAndView nearFollowedBusinessOpportunity(HttpServletRequest request, HttpServletResponse response, QueryCustomer queryCustomer) {
    Integer userId = (Integer)request.getSession().getAttribute("userId");
    List saleStages = this.manageReportService.getSaleStages();
    Map model = new HashMap();
    String sFlag = request.getParameter("sFlag");
    String customerName2 = "客户名称";
    if ((!StringUtils.isEmpty(sFlag)) && ("1".equals(sFlag))) {
      customerName2 = request.getParameter("customerName2");
    }
    model.put("customerName2", customerName2);
    model.put("sFlag", sFlag);
    QueryCustomer qCustomer = null;
    if ((!StringUtils.isEmpty(sFlag)) && ("2".equals(sFlag))) {
      qCustomer = queryCustomer;
    }
    model.put("queryCustomer", qCustomer);
    if ((request.getParameter("see") != null) && (!request.getParameter("see").trim().equals("")) && (request.getParameter("customerId") != null)) {
      String customerId = request.getParameter("customerId");
      String sign = request.getParameter("sign");
      model.put("customerId", customerId);
      model.put("contracts", this.contractService.getContractByCustomerId(Integer.valueOf(Integer.parseInt(customerId))));
      model.put("result", request.getParameter("result"));
      model.put("records", this.customerService.getCustomerInfoRecords());
      model.put("ranges", this.customerService.getCustomerDictionaryRanges());
      model.put("saleStages", this.saleStageSetService.getSaleStages());

      model.put("saleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "0"));
      model.put("hisRootSaleRecords", this.saleRecordService.getCloseSaleRcordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId))));
      model.put("hisSaleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "1"));
      model.put("careSaleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "2"));
      model.put("hangupSaleRecords", this.saleRecordService.getSaleRecordsByCustomerId(Integer.valueOf(Integer.parseInt(customerId)), 0, "3"));
      String realPath = getServletContext().getRealPath("/");
      if (!StringUtils.isEmpty(customerId)) {
        model.put("customer", this.customerService.getCustomerById2(Integer.valueOf(Integer.parseInt(customerId)), realPath, userId));
        model.put("linkmanRanges", this.linkmanService.getLinkmanDictionaryRanges());
        model.put("saleInfo", this.customerService.getCustomerSaleInfoById(Integer.valueOf(Integer.parseInt(customerId))));

        CustomerLimitForm customerLimitForm = new CustomerLimitForm();
        customerLimitForm = this.customerService.getCustomerLimit(userId);
        if (this.assessmentTypeService.isExpUser(userId)) {
          model.put("isExpUser", "1");
        }
        model.put("customerLimitForm", customerLimitForm);
        model.put("discardLimitNum", this.customerService.getDiscardCustomerNum(userId));

        if ((!StringUtils.isEmpty(sign)) && ("11".equals(sign))) {
          this.customerService.updateViewCustomerDate(Integer.valueOf(Integer.parseInt(customerId)));
        }
      }
    }
    model.put("saleStages", saleStages);
    Page page = new Page();
    page.getPageList(this.customerService.getNearFollowedBusinessOpportunityCount(userId, customerName2, qCustomer).intValue(), Integer.valueOf(10), request);
    model.put("customers", this.customerService.getNearFollowedBusinessOpportunity(userId, page, customerName2, qCustomer));
    return new ModelAndView(getNearFollowedBusinessOpportunity(), model);
  }
  public ModelAndView advancedQueryNameCustomer(HttpServletRequest request, HttpServletResponse response) {
    Map model = new HashMap();
    Integer userId = (Integer)request.getSession().getAttribute("userId");
    List users = new ArrayList();

    if (userId != null) {
      String deptIds = this.departmentService.getCurrentDeptIdAndSubDeptIdsByUserId(userId);
      users = this.userService.getActivityUsersByDeptIds(deptIds);
    }
    model.put("users", users);

    model.put("ranges", this.customerService.getCustomerDictionaryRanges());
    return new ModelAndView(getAdvancedQueryNameCustomer(), model);
  }
  public ModelAndView advancedQueryShareCustomer(HttpServletRequest request, HttpServletResponse response) {
    Map model = new HashMap();
    Integer userId = (Integer)request.getSession().getAttribute("userId");
    List users = new ArrayList();
    if (userId != null) {
      String deptIds = this.departmentService.getCurrentDeptIdAndSubDeptIdsByUserId(userId);
      users = this.userService.getActivityUsersByDeptIds(deptIds);
    }
    model.put("users", users);

    model.put("ranges", this.customerService.getCustomerDictionaryRanges());
    return new ModelAndView(getAdvancedQueryShareCustomer(), model);
  }
  public ModelAndView advancedQueryNear(HttpServletRequest request, HttpServletResponse response) {
    Map model = new HashMap();
    model.put("ranges", this.customerService.getCustomerDictionaryRanges());
    return new ModelAndView(getAdvancedQueryNear(), model);
  }
  public ModelAndView advancedQueryMySucceedContract(HttpServletRequest request, HttpServletResponse response) {
    Map model = new HashMap();
    model.put("ranges", this.customerService.getCustomerDictionaryRanges());
    return new ModelAndView(getAdvancedQueryMySucceedContract(), model);
  }
  public ModelAndView advancedQueryMyHangUp(HttpServletRequest request, HttpServletResponse response) {
    Map model = new HashMap();
    model.put("ranges", this.customerService.getCustomerDictionaryRanges());
    return new ModelAndView(getAdvancedQueryMyHangUp(), model);
  }
  public ModelAndView advancedQueryMyGiveUp(HttpServletRequest request, HttpServletResponse response) {
    Map model = new HashMap();
    model.put("ranges", this.customerService.getCustomerDictionaryRanges());
    return new ModelAndView(getAdvancedQueryMyGiveUp(), model);
  }
  public ModelAndView advancedQuerySucceedContract(HttpServletRequest request, HttpServletResponse response) {
    Map model = new HashMap();
    Integer userId = (Integer)request.getSession().getAttribute("userId");
    List users = new ArrayList();
    if (userId != null) {
      String deptIds = this.departmentService.getCurrentDeptIdAndSubDeptIdsByUserId(userId);
      users = this.userService.getActivityUsersByDeptIds(deptIds);
    }
    model.put("users", users);

    model.put("ranges", this.customerService.getCustomerDictionaryRanges());
    return new ModelAndView(getAdvancedQuerySucceedContract(), model);
  }

  protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
    binder.registerCustomEditor(Date.class, new DatePropertyEditor());
    binder.registerCustomEditor(BigDecimal.class, new BigDecimalPropertyEditor());
  }
}